package flyweight

type FlyWeight struct {
	Name string
}

func NewFlyWeight(name string) *FlyWeight {
	return &FlyWeight{
		Name: name,
	}
}

type FlyWeightFactory struct {
	pool map[string]*FlyWeight
}

func NewFlyWeightFactory() *FlyWeightFactory {
	return &FlyWeightFactory{
		pool: make(map[string]*FlyWeight),
	}
}

func (f *FlyWeightFactory) GetFlyWeight(name string) *FlyWeight {
	fw, ok := f.pool[name]
	if !ok {
		fw = NewFlyWeight(name)
		f.pool[name] = fw
	}
	return fw
}
